package guoanmaker.operator.business.repository;


import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorContractType;

public interface OperatorContractTypeRepository extends JpaRepository<OperatorContractType, String>,JpaSpecificationExecutor<OperatorContractType>{
	public List<OperatorContractType> findByName(String name);
	public List<OperatorContractType> findByNameAndGuideEquals(String name,String guide);
	@Query("select o from OperatorContractType  o  where  o.name=:name and  (o.guide !='1' or o.guide is NULL or o.guide='')")
	public List<OperatorContractType> findByNAndG(@Param("name")String name);
	public List<OperatorContractType> findByNameLikeOrderByCreateDateDesc(String name);
	@Query("select o from OperatorContractType  o  where  o.name like %:name%  and  (o.guide !='1' or o.guide is NULL or o.guide='') order by o.createDate desc")
	public List<OperatorContractType> findByNameLikeAndGuideNotOrderByCreateDateDesc(@Param("name")String name);
	public List<OperatorContractType> findByNameLikeAndGuideEqualsOrderByCreateDateDesc(String name,String guide);
	public List<OperatorContractType> findByNameAndIdNot(String name,String id);
	
	public Page<OperatorContractType> findAll(Pageable pageable);
	
	@Transactional
	@Modifying
	@Query("update OperatorContractType set useCount=useCount + 1 where id=:id")
	public void addContractTypeCount(@Param("id") String id);
	
	@Transactional
	@Modifying
	@Query("update OperatorContractType set useCount=useCount - 1 where id=:id")
	public void divContractTypeCount(@Param("id") String id);
	
	@Query("select count(*) from OperatorContractType  o  where o.guide='1'")
	public  int  selectByGuideEquals();
	@Query("select count(*) from OperatorContractType  o  where o.guide !='1' or o.guide is NULL or o.guide=''")
	public  int  selectByGuidenotEquals();
	
}
